package com.why.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.why.dto.ArticlePageDTO;
import com.why.pojo.Article;
import com.why.result.PageResult;
import com.why.service.ArticleService;
import com.why.mapper.ArticleMapper;
import com.why.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* @author 王-自信
* @description 针对表【article】的数据库操作Service实现
* @createDate 2024-11-26 16:06:48
*/
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article>
    implements ArticleService{

    @Autowired
    private ArticleMapper articleMapper;
    @Override
    public List<Article> getAll() {
        List<Article> list = articleMapper.selectList(null);
        return list;
    }

    @Override
    public void add(Article article) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer uid = (Integer) map.get("id");
        articleMapper.add(article,uid);
    }

    @Override
    public PageResult<Article> pageQuery(ArticlePageDTO articlePageDTO) {
        PageResult<Article> pageResult = new PageResult();
        PageHelper.startPage(articlePageDTO.getPageNum(),articlePageDTO.getPageSize());
        Page<Article> page = articleMapper.pageQuery(articlePageDTO);
        pageResult.setTotal((int) page.getTotal());
        pageResult.setItems(page.getResult());
        return pageResult;
    }

    @Override
    public void updateArticle(Article article) {
        articleMapper.updateArticle(article);
    }

    @Override
    public void delete(List<Integer> ids) {
        articleMapper.deleteByIds(ids);
//        for(Integer id:ids){
//            if (articleMapper.selectById(id)!=null){
//                articleMapper.
//            }
//        }
    }
}




